home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWMenu / FWMnuItm.h < prev    next >
Encoding:
Text File  |  1996-09-17  |  10.5 KB  |  356 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWMnuItm.h
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWMNUITM_H
  11. #define FWMNUITM_H
  12.  
  13. #ifndef FWMENUS_K
  14. #include "FWMenus.k"
  15. #endif
  16.  
  17. #ifndef FWODTYPS_H
  18. #include "FWODTyps.h"
  19. #endif
  20.  
  21. // ----- Foundation Includes -----
  22.  
  23. #ifndef FWSTRS_H
  24. #include "FWStrs.h"
  25. #endif
  26.  
  27. #ifndef FWSTREAM_H
  28. #include "FWStream.h"
  29. #endif
  30.  
  31. #ifndef FWTCOLL_H
  32. #include "FWTColl.h"
  33. #endif
  34.  
  35. // ----- OpenDoc Includes -----
  36.  
  37. #ifndef SOM_Module_OpenDoc_Commands_defined
  38. #include <CmdDefs.xh>
  39. #endif
  40.  
  41. //========================================================================================
  42. //    Forward Declarations
  43. //========================================================================================
  44.  
  45. class FW_CPullDownMenu;
  46. class FW_CString;
  47. class FW_CMenuBar;
  48.  
  49. //========================================================================================
  50. //    Defines
  51. //========================================================================================
  52.  
  53. typedef short FW_MenuKey;
  54.  
  55. #ifdef FW_BUILD_MAC
  56. const FW_MenuKey FW_kPrivMacMenuKeyCharMask         = 0x00FF;
  57. const short FW_kPrivMacScriptCodeKeyEquivalent         = 28;    // key equiv value of $1C indicates that the icon field contains a script code
  58. #endif
  59.  
  60. const ODMenuID FW_kFirstMenuID = 4;
  61.  
  62.  
  63.  
  64. //========================================================================================
  65. //    class FW_CMenuItem
  66. //========================================================================================
  67.  
  68. class FW_CMenuItem
  69. {
  70. public:
  71.     FW_DECLARE_CLASS
  72.     FW_DECLARE_AUTO(FW_CMenuItem)
  73.  
  74. //----------------------------------------------------------------------------------------
  75. //    Constructors/Destructors
  76. //
  77. public:
  78.     FW_CMenuItem(Environment* ev, 
  79.                 FW_CReadableStream& stream);
  80.     FW_CMenuItem(Environment* ev, 
  81.                 FW_CPullDownMenu* ownerMenu, 
  82.                 short index);
  83.     
  84.     virtual     ~FW_CMenuItem();
  85.  
  86. //----------------------------------------------------------------------------------------
  87. //    New API
  88. //
  89. public:
  90.     //----- Getters/setters -----
  91.     ODCommandID            GetCommandID(Environment* ev) const;
  92.     
  93.     FW_CPullDownMenu*    GetOwnerMenu(Environment* ev) const;
  94.     short                GetIndex(Environment* ev) const;
  95.  
  96.     //----- Archiving -----
  97.     virtual void        Flatten(Environment* ev, FW_CWritableStream& stream);    
  98.     static void*        Read(FW_CReadableStream& stream, FW_ClassTypeConstant type);
  99.     static void         Write(FW_CWritableStream& stream, FW_ClassTypeConstant type, const void *object);
  100.     
  101. //----------------------------------------------------------------------------------------
  102. //    Implementation only
  103. //
  104. public:
  105.     virtual void            PrivAttach(Environment* ev, FW_CMenuBar* menuBar);
  106.     virtual void            PrivDetach(Environment* ev, FW_CMenuBar* menuBar);
  107.     virtual void            PrivDisableAll(Environment* ev);
  108.     virtual void            PrivEnableAll(Environment* ev);
  109.     virtual FW_CMenuItem*     PrivGetMenuItem(Environment* ev, ODCommandID commandID) const;
  110.     
  111.     virtual FW_CPullDownMenu* PrivFindMenuWithID(Environment* ev, ODMenuID menuID) const;
  112.     
  113.     void                    PrivSetIndex(Environment* ev, short newIndex);
  114.     
  115. //----------------------------------------------------------------------------------------
  116. //    Data Members
  117. //
  118. protected:
  119. #ifdef FW_BUILD_MAC
  120.     ODCommandID            fCommandID;        // On windows call the toolbox
  121. #endif
  122.     FW_CPullDownMenu*    fOwnerMenu;
  123.     short                fIndex;            // one-based
  124. };
  125.  
  126.  
  127. //========================================================================================
  128. //    class FW_CSeparatorItem
  129. //========================================================================================
  130.  
  131. class FW_CSeparatorItem : public FW_CMenuItem
  132. {
  133. public:
  134.     FW_DECLARE_CLASS
  135.     FW_DECLARE_AUTO(FW_CSeparatorItem)
  136.  
  137. //----------------------------------------------------------------------------------------
  138. //    Constructors/Destructors
  139. //
  140. public:
  141.     FW_CSeparatorItem(Environment* ev, 
  142.                 FW_CReadableStream& stream);
  143.     FW_CSeparatorItem(Environment* ev, 
  144.                 FW_CPullDownMenu* ownerMenu, 
  145.                 short index);
  146.                 
  147.     virtual     ~FW_CSeparatorItem();
  148.  
  149. protected:
  150.     void        InitSeparator(Environment* ev, const ODPlatformMenu& platformMenu);
  151.     
  152. //----------------------------------------------------------------------------------------
  153. //    Inherited API
  154. //
  155. public:
  156.     static void*        Read(FW_CReadableStream& stream, FW_ClassTypeConstant type);
  157.  
  158. //----------------------------------------------------------------------------------------
  159. //    Implementation only
  160. //
  161. public:
  162.     virtual void        PrivDisableAll(Environment* ev);
  163.     virtual void        PrivEnableAll(Environment* ev);
  164. };
  165.  
  166.  
  167.  
  168. //========================================================================================
  169. //    class FW_CTextItem
  170. //========================================================================================
  171.  
  172. class FW_CTextItem : public FW_CMenuItem
  173. {
  174. public:
  175.     FW_DECLARE_CLASS
  176.     FW_DECLARE_AUTO(FW_CTextItem)
  177.  
  178. //----------------------------------------------------------------------------------------
  179. //    Constructors/Destructors
  180. //
  181. public:
  182.     FW_CTextItem(Environment* ev, 
  183.                 FW_CReadableStream& stream);
  184.     FW_CTextItem(Environment* ev,
  185.                 FW_CPullDownMenu* ownerMenu, 
  186.                 short index,            
  187.                 const FW_CString& text,
  188.                 ODCommandID commandID,
  189.                 FW_MenuKey menuKey = FW_kNoKeyEquivalent);
  190.     virtual ~FW_CTextItem();
  191.  
  192. //----------------------------------------------------------------------------------------
  193. //    Inherited API
  194. //
  195. public:
  196.     //----- Archiving -----
  197.     virtual void        Flatten(Environment* ev, FW_CWritableStream& stream);
  198.     static void*        Read(FW_CReadableStream& stream, FW_ClassTypeConstant type);
  199.     
  200. //----------------------------------------------------------------------------------------
  201. //    Implementation only
  202. //
  203. public:
  204. #ifdef FW_BUILD_MAC
  205.     virtual void        PrivAttach(Environment* ev, FW_CMenuBar* menuBar);
  206.     virtual void        PrivDetach(Environment* ev, FW_CMenuBar* menuBar);
  207. #endif
  208. private:
  209.     void                PrivInitTextItem(Environment* ev,
  210.                                          const ODPlatformMenu&    platformMenu,
  211.                                           const FW_CString& text,
  212.                                          ODCommandID commandID,
  213.                                           FW_MenuKey menuKey);
  214.                               
  215. };
  216.  
  217.  
  218.  
  219. //========================================================================================
  220. //    class FW_CToggleItem
  221. //========================================================================================
  222.  
  223. class FW_CToggleItem : public FW_CTextItem
  224. {
  225. public:
  226.     FW_DECLARE_CLASS
  227.     FW_DECLARE_AUTO(FW_CToggleItem)
  228.  
  229. //----------------------------------------------------------------------------------------
  230. //    Constructors/Destructors
  231. //
  232. public:
  233.     FW_CToggleItem(Environment* ev, 
  234.                 FW_CReadableStream& stream);
  235.     FW_CToggleItem(Environment* ev,
  236.                 FW_CPullDownMenu* ownerMenu, 
  237.                 short index,            
  238.                 const FW_CString& trueText,
  239.                 const FW_CString& falseText,
  240.                 ODCommandID commandID,
  241.                 FW_MenuKey menuKey = FW_kNoKeyEquivalent);
  242.     virtual     ~FW_CToggleItem();
  243.  
  244. //----------------------------------------------------------------------------------------
  245. //    New API
  246. //
  247. public:
  248.     void                ToggleItem(Environment* ev, FW_Boolean newState);
  249.     
  250.     //----- Archiving -----
  251.     virtual void        Flatten(Environment* ev, FW_CWritableStream& stream);
  252.     static void*        Read(FW_CReadableStream& stream, FW_ClassTypeConstant type);
  253.  
  254. //----------------------------------------------------------------------------------------
  255. //    Data Members
  256. //
  257. private:
  258.     FW_Boolean            fToggleState;
  259.     FW_CString            fOtherText;
  260. };
  261.  
  262.  
  263.  
  264. //========================================================================================
  265. //    class FW_CSubMenuItem
  266. //========================================================================================
  267.  
  268. class FW_CSubMenuItem : public FW_CMenuItem
  269. {
  270. public:
  271.     FW_DECLARE_CLASS
  272.     FW_DECLARE_AUTO(FW_CSubMenuItem)
  273.  
  274. //----------------------------------------------------------------------------------------
  275. //    Constructors/Destructors
  276. //
  277. public:
  278.     FW_CSubMenuItem(Environment* ev, 
  279.                 FW_CReadableStream& stream);
  280.     FW_CSubMenuItem(Environment* ev,
  281.                 FW_CPullDownMenu* ownerMenu, 
  282.                 short index,
  283.                 FW_CPullDownMenu* adoptSubMenu);
  284.     virtual     ~FW_CSubMenuItem();
  285.  
  286. //----------------------------------------------------------------------------------------
  287. //    New API
  288. //
  289. public:
  290.     //----- Getters/setters -----
  291.     FW_CPullDownMenu*    GetSubMenu(Environment* ev) const;
  292.  
  293.     //----- Archiving -----
  294.     virtual void        Flatten(Environment* ev, FW_CWritableStream& stream);
  295.     static void*        Read(FW_CReadableStream& stream, FW_ClassTypeConstant type);
  296.  
  297. //----------------------------------------------------------------------------------------
  298. //    Implementation only
  299. //
  300. public:
  301.     virtual void            PrivAttach(Environment* ev, FW_CMenuBar* menuBar);
  302.     virtual void            PrivDetach(Environment* ev, FW_CMenuBar* menuBar);
  303.     virtual void            PrivDisableAll(Environment* ev);
  304.     virtual void            PrivEnableAll(Environment* ev);
  305.     virtual FW_CMenuItem*     PrivGetMenuItem(Environment* ev, ODCommandID commandID) const;
  306.  
  307.     virtual FW_CPullDownMenu* PrivFindMenuWithID(Environment* ev, ODMenuID menuID) const;
  308.  
  309. private:
  310.     void                    PrivInitSubMenu(Environment* ev, const ODPlatformMenu&    platformMenu);
  311.     
  312. //----------------------------------------------------------------------------------------
  313. //    Data Members
  314. //
  315. private:
  316.     FW_CPullDownMenu*    fSubMenu;
  317. };
  318.  
  319. //========================================================================================
  320. //    FW_CMenuItem inlines
  321. //========================================================================================
  322.  
  323. //----------------------------------------------------------------------------------------
  324. //    FW_CMenuItem::GetOwnerMenu
  325. //----------------------------------------------------------------------------------------
  326. inline FW_CPullDownMenu* FW_CMenuItem::GetOwnerMenu(Environment*) const
  327. {
  328.     return fOwnerMenu;
  329. }
  330.  
  331. //----------------------------------------------------------------------------------------
  332. //    FW_CMenuItem::GetIndex
  333. //----------------------------------------------------------------------------------------
  334. inline short FW_CMenuItem::GetIndex(Environment*) const
  335. {
  336.     return fIndex;
  337. }
  338.  
  339. //----------------------------------------------------------------------------------------
  340. //    FW_CSubMenuItem::GetSubMenu
  341. //----------------------------------------------------------------------------------------
  342. inline FW_CPullDownMenu* FW_CSubMenuItem::GetSubMenu(Environment*) const
  343. {
  344.     return fSubMenu;
  345. }
  346.  
  347. //----------------------------------------------------------------------------------------
  348. //    FW_CMenuItem::PrivSetIndex
  349. //----------------------------------------------------------------------------------------
  350. inline void FW_CMenuItem::PrivSetIndex(Environment*, short newIndex)
  351. {
  352.     fIndex = newIndex;
  353. }
  354.  
  355. #endif
  356.